package com.duowei.dw_pos.dialog;

import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v7.app.AppCompatDialogFragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.WindowManager;
import android.widget.AdapterView;
import android.widget.GridView;

import com.duowei.dw_pos.R;
import com.duowei.dw_pos.adapter.CustomerAdapter;
import com.duowei.dw_pos.bean.GKLX;

import org.litepal.crud.DataSupport;

import java.util.List;

/**
 * A simple {@link Fragment} subclass.
 */
public class CustomerDialogFragment extends AppCompatDialogFragment implements AdapterView.OnItemClickListener {

    private List<GKLX> mGklxes;

    public CustomerDialogFragment() {
        // Required empty public constructor
    }

    public static CustomerDialogFragment newInstance() {
        Bundle args = new Bundle();
        CustomerDialogFragment fragment = new CustomerDialogFragment();
        fragment.setArguments(args);
        return fragment;
    }

    public interface GvClick{
        void onGvClick(String gklx);
    }
    private GvClick mGvClick;
    public void setOnGvClick(GvClick click){
        mGvClick=click;
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        // Inflate the layout for this fragment
        View inflate = inflater.inflate(R.layout.customerstytle, container, false);
        mGklxes = DataSupport.findAll(GKLX.class);
        GridView gv = (GridView) inflate.findViewById(R.id.gridView);
        CustomerAdapter adapter = new CustomerAdapter(getActivity(), mGklxes);
        gv.setAdapter(adapter);
        gv.setOnItemClickListener(this);
        return inflate;
    }

    @Override
    public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
        mGvClick.onGvClick(mGklxes.get(i).getGKLX());
        dismiss();
    }
}
